home *** CD-ROM | disk | FTP | other *** search
/ Champak 140 / (Vol 140) Sep 19 2011.iso / Games / top_that_pizza.swf / scripts / FComboBoxSymbol.as < prev    next >
Text File  |  2011-09-19  |  15KB  |  504 lines

  1. function FComboBoxClass()
  2. {
  3.    var _loc1_ = this;
  4.    _global._popUpLevel = _global._popUpLevel != undefined ? _global._popUpLevel + 1 : 20000;
  5.    _loc1_.superHolder = _root.createEmptyMovieClip("superHolder" + _popUpLevel,_popUpLevel);
  6.    var _loc3_ = _loc1_.superHolder.createEmptyMovieClip("testCont",20000);
  7.    var testBox = _loc3_.attachMovie("FBoundingBoxSymbol","boundingBox_mc",0);
  8.    if(testBox._name == undefined)
  9.    {
  10.       _loc1_.superHolder.removeMovieClip();
  11.       _loc1_.superHolder = _loc1_._parent.createEmptyMovieClip("superHolder" + _popUpLevel,_popUpLevel);
  12.    }
  13.    else
  14.    {
  15.       _loc3_.removeMovieClip();
  16.    }
  17.    if(_loc1_.rowCount == undefined)
  18.    {
  19.       _loc1_.rowCount = 8;
  20.       _loc1_.editable = false;
  21.    }
  22.    _loc1_.itemSymbol = "FComboBoxItemSymbol";
  23.    _loc1_.init();
  24.    _loc1_.permaScrollBar = false;
  25.    _loc1_.proxyBox_mc.gotoAndStop(1);
  26.    _loc1_.width = _loc1_._width;
  27.    _loc1_.height = _loc1_.proxyBox_mc._height * _loc1_._yscale / 100;
  28.    var _loc2_ = 0;
  29.    while(_loc2_ < _loc1_.labels.length)
  30.    {
  31.       _loc1_.addItem(_loc1_.labels[_loc2_],_loc1_.data[_loc2_]);
  32.       _loc2_ = _loc2_ + 1;
  33.    }
  34.    _loc1_.lastSelected = 0;
  35.    _loc1_.selectItem(0);
  36.    _loc1_._xscale = _loc1_._yscale = 100;
  37.    _loc1_.opened = false;
  38.    _loc1_.setSize(_loc1_.width);
  39.    _loc1_.highlightTop(false);
  40.    if(_loc1_.changeHandler.length > 0)
  41.    {
  42.       _loc1_.setChangeHandler(_loc1_.changeHandler);
  43.    }
  44.    _loc1_.onUnload = function()
  45.    {
  46.       this.superHolder.removeMovieClip();
  47.    };
  48.    _loc1_.setSelectedIndex(0,false);
  49.    _loc1_.value = "";
  50.    _loc1_.focusEnabled = true;
  51.    _loc1_.changeFlag = false;
  52. }
  53. FComboBoxClass.prototype = new FScrollSelectListClass();
  54. Object.registerClass("FComboBoxSymbol",FComboBoxClass);
  55. FComboBoxClass.prototype.modelChanged = function(eventObj)
  56. {
  57.    var _loc1_ = this;
  58.    super.modelChanged(eventObj);
  59.    var _loc2_ = eventObj.event;
  60.    if(_loc2_ == "addRows" || _loc2_ == "deleteRows")
  61.    {
  62.       var diff = eventObj.lastRow - eventObj.firstRow + 1;
  63.       var mode = _loc2_ != "addRows" ? -1 : 1;
  64.       var _loc3_ = _loc1_.getLength();
  65.       var lenBefore = _loc3_ - mode * diff;
  66.       if(_loc1_.rowCount > lenBefore || _loc1_.rowCount > _loc3_)
  67.       {
  68.          _loc1_.invalidate("setSize");
  69.       }
  70.       if(_loc1_.getSelectedIndex() == undefined)
  71.       {
  72.          _loc1_.setSelectedIndex(0,false);
  73.       }
  74.    }
  75.    else if(_loc2_ == "updateAll")
  76.    {
  77.       _loc1_.invalidate("setSize");
  78.    }
  79. };
  80. FComboBoxClass.prototype.removeAll = function()
  81. {
  82.    var _loc1_ = this;
  83.    if(_loc1_.enable)
  84.    {
  85.       super.removeAll();
  86.       if(_loc1_.editable)
  87.       {
  88.          _loc1_.value = "";
  89.       }
  90.       _loc1_.invalidate("setSize");
  91.    }
  92. };
  93. FComboBoxClass.prototype.setSize = function(w)
  94. {
  95.    var _loc1_ = this;
  96.    var _loc2_ = w;
  97.    if(!(_loc2_ == undefined || typeof _loc2_ != "number" || _loc2_ <= 0 || !_loc1_.enable))
  98.    {
  99.       _loc1_.proxyBox_mc._width = _loc2_;
  100.       _loc1_.container_mc.removeMovieClip();
  101.       _loc1_.measureItmHgt();
  102.       _loc1_.container_mc = _loc1_.superHolder.createEmptyMovieClip("container",3);
  103.       _loc1_.container_mc.tabChildren = false;
  104.       _loc1_.setPopUpLocation(_loc1_.container_mc);
  105.       _loc1_.container_mc.attachMovie("FBoundingBoxSymbol","boundingBox_mc",0);
  106.       _loc1_.boundingBox_mc = _loc1_.container_mc.boundingBox_mc;
  107.       _loc1_.boundingBox_mc.component = _loc1_;
  108.       _loc1_.registerSkinElement(_loc1_.boundingBox_mc.boundingBox,"background");
  109.       _loc1_.proxyBox_mc._height = _loc1_.itmHgt;
  110.       _loc1_.numDisplayed = Math.min(_loc1_.rowCount,_loc1_.getLength());
  111.       if(_loc1_.numDisplayed < 3)
  112.       {
  113.          _loc1_.numDisplayed = Math.min(3,_loc1_.getLength());
  114.       }
  115.       _loc1_.height = _loc1_.numDisplayed * (_loc1_.itmHgt - 2) + 2;
  116.       super.setSize(_loc2_,_loc1_.height);
  117.       _loc1_.attachMovie("DownArrow","downArrow",10);
  118.       _loc1_.downArrow._y = 0;
  119.       _loc1_.downArrow._width = _loc1_.itmHgt;
  120.       _loc1_.downArrow._height = _loc1_.itmHgt;
  121.       _loc1_.downArrow._x = _loc1_.proxyBox_mc._width - _loc1_.downArrow._width;
  122.       _loc1_.setEditable(_loc1_.editable);
  123.       _loc1_.container_mc._visible = _loc1_.opened;
  124.       _loc1_.highlightTop(false);
  125.       _loc1_.fader = _loc1_.superHolder.attachMovie("FBoundingBoxSymbol","faderX",4);
  126.       _loc1_.registerSkinElement(_loc1_.fader.boundingBox,"background");
  127.       _loc1_.fader._width = _loc1_.width;
  128.       _loc1_.fader._height = _loc1_.height;
  129.       _loc1_.fader._visible = false;
  130.    }
  131. };
  132. FComboBoxClass.prototype.setDataProvider = function(dp)
  133. {
  134.    super.setDataProvider(dp);
  135.    this.invalidate("setSize");
  136.    this.setSelectedIndex(0);
  137. };
  138. FComboBoxClass.prototype.getValue = function()
  139. {
  140.    if(this.editable)
  141.    {
  142.       return this.fLabel_mc.getLabel();
  143.    }
  144.    return super.getValue();
  145. };
  146. FComboBoxClass.prototype.getRowCount = function()
  147. {
  148.    return this.rowCount;
  149. };
  150. FComboBoxClass.prototype.setRowCount = function(count)
  151. {
  152.    var _loc1_ = this;
  153.    var _loc3_ = count;
  154.    _loc1_.rowCount = _loc1_.getLength() <= _loc3_ ? _loc3_ : Math.max(_loc3_,3);
  155.    _loc1_.setSize(_loc1_.width);
  156.    var _loc2_ = _loc1_.getLength();
  157.    if(_loc2_ - _loc1_.getScrollPosition() < _loc1_.rowCount)
  158.    {
  159.       _loc1_.setScrollPosition(_loc2_ - Math.min(_loc1_.rowCount,_loc2_));
  160.       _loc1_.invalidate("updateControl");
  161.    }
  162. };
  163. FComboBoxClass.prototype.setEditable = function(editableFlag)
  164. {
  165.    var _loc1_ = this;
  166.    if(_loc1_.enable)
  167.    {
  168.       _loc1_.editable = editableFlag;
  169.       if(!_loc1_.editable)
  170.       {
  171.          _loc1_.onPress = _loc1_.pressHandler;
  172.          _loc1_.useHandCursor = false;
  173.          _loc1_.trackAsMenu = true;
  174.          _loc1_.attachMovie("FComboBoxItemSymbol","fLabel_mc",5,{controller:_loc1_,itemNum:-1});
  175.          _loc1_.fLabel_mc.onRollOver = undefined;
  176.          _loc1_.fLabel_mc.setSize(_loc1_.width - _loc1_.itmHgt + 1,_loc1_.itmHgt);
  177.          _loc1_.topLabel = _loc1_.getSelectedItem();
  178.          _loc1_.fLabel_mc.drawItem(_loc1_.topLabel,false);
  179.          _loc1_.highlightTop(false);
  180.       }
  181.       else
  182.       {
  183.          _loc1_.attachMovie("FLabelSymbol","fLabel_mc",5);
  184.          _loc1_.fLabel_txt = _loc1_.fLabel_mc.labelField;
  185.          _loc1_.fLabel_txt.type = "input";
  186.          _loc1_.fLabel_txt._x = 4;
  187.          _loc1_.fLabel_txt.onSetFocus = _loc1_.onLabelFocus;
  188.          _loc1_.fLabel_mc.setSize(_loc1_.width - _loc1_.itmHgt - 3);
  189.          delete _loc1_.onPress;
  190.          _loc1_.fLabel_txt.onKillFocus = function()
  191.          {
  192.             this._parent._parent.myOnKillFocus();
  193.          };
  194.          _loc1_.fLabel_mc.setLabel(_loc1_.value);
  195.          _loc1_.fLabel_txt.onChanged = function()
  196.          {
  197.             this._parent._parent.findInputText();
  198.          };
  199.          _loc1_.downArrow.onPress = _loc1_.buttonPressHandler;
  200.          _loc1_.downArrow.useHandCursor = false;
  201.          _loc1_.downArrow.trackAsMenu = true;
  202.       }
  203.    }
  204. };
  205. FComboBoxClass.prototype.setEnabled = function(enabledFlag)
  206. {
  207.    var _loc1_ = this;
  208.    var _loc2_ = enabledFlag;
  209.    _loc2_ = !(_loc2_ == undefined || typeof _loc2_ != "boolean") ? _loc2_ : true;
  210.    super.setEnabled(_loc2_);
  211.    _loc1_.registerSkinElement(_loc1_.boundingBox_mc.boundingBox,"background");
  212.    _loc1_.proxyBox_mc.gotoAndStop(!_loc1_.enable ? "disabled" : "enabled");
  213.    _loc1_.downArrow.gotoAndStop(!_loc1_.enable ? 3 : 1);
  214.    if(_loc1_.editable)
  215.    {
  216.       _loc1_.fLabel_txt.type = !_loc2_ ? "dynamic" : "input";
  217.       _loc1_.fLabel_txt.selectable = _loc2_;
  218.    }
  219.    else if(_loc2_)
  220.    {
  221.       _loc1_.fLabel_mc.drawItem(_loc1_.topLabel,false);
  222.       _loc1_.setSelectedIndex(_loc1_.getSelectedIndex(),false);
  223.    }
  224.    _loc1_.fLabel_mc.setEnabled(_loc1_.enable);
  225.    _loc1_.fLabel_txt.onSetFocus = !_loc2_ ? undefined : _loc1_.onLabelFocus;
  226. };
  227. FComboBoxClass.prototype.setSelectedIndex = function(index, flag)
  228. {
  229.    var _loc1_ = this;
  230.    super.setSelectedIndex(index,flag);
  231.    if(!_loc1_.editable)
  232.    {
  233.       _loc1_.topLabel = _loc1_.getSelectedItem();
  234.       _loc1_.fLabel_mc.drawItem(_loc1_.topLabel,false);
  235.    }
  236.    else
  237.    {
  238.       _loc1_.value = flag == undefined ? _loc1_.getSelectedItem().label : "";
  239.       _loc1_.fLabel_mc.setLabel(_loc1_.value);
  240.    }
  241.    _loc1_.invalidate("updateControl");
  242. };
  243. FComboBoxClass.prototype.setValue = function(value)
  244. {
  245.    var _loc1_ = this;
  246.    if(_loc1_.editable)
  247.    {
  248.       _loc1_.fLabel_mc.setLabel(value);
  249.       _loc1_.value = value;
  250.    }
  251. };
  252. FComboBoxClass.prototype.pressHandler = function()
  253. {
  254.    var _loc1_ = this;
  255.    _loc1_.focusRect.removeMovieClip();
  256.    if(_loc1_.enable)
  257.    {
  258.       if(!_loc1_.opened)
  259.       {
  260.          _loc1_.onMouseUp = _loc1_.releaseHandler;
  261.       }
  262.       else
  263.       {
  264.          _loc1_.onMouseUp = undefined;
  265.       }
  266.       _loc1_.changeFlag = false;
  267.       if(!_loc1_.focused)
  268.       {
  269.          _loc1_.pressFocus();
  270.          _loc1_.clickFilter = !_loc1_.editable ? true : false;
  271.       }
  272.       if(!_loc1_.clickFilter)
  273.       {
  274.          _loc1_.openOrClose(!_loc1_.opened);
  275.       }
  276.       else
  277.       {
  278.          _loc1_.clickFilter = false;
  279.       }
  280.    }
  281. };
  282. FComboBoxClass.prototype.clickHandler = function(itmNum)
  283. {
  284.    var _loc1_ = this;
  285.    if(!_loc1_.focused)
  286.    {
  287.       if(_loc1_.editable)
  288.       {
  289.          _loc1_.fLabel_txt.onKillFocus = undefined;
  290.       }
  291.       _loc1_.pressFocus();
  292.    }
  293.    super.clickHandler(itmNum);
  294.    _loc1_.selectionHandler(itmNum);
  295.    _loc1_.onMouseUp = _loc1_.releaseHandler;
  296. };
  297. FComboBoxClass.prototype.highlightTop = function(flag)
  298. {
  299.    var _loc1_ = this;
  300.    if(!_loc1_.editable)
  301.    {
  302.       _loc1_.fLabel_mc.drawItem(_loc1_.topLabel,flag);
  303.    }
  304. };
  305. FComboBoxClass.prototype.myOnSetFocus = function()
  306. {
  307.    super.myOnSetFocus();
  308.    this.fLabel_mc.highlight_mc.gotoAndStop("enabled");
  309.    this.highlightTop(true);
  310. };
  311. FComboBoxClass.prototype.drawFocusRect = function()
  312. {
  313.    var _loc1_ = this;
  314.    _loc1_.drawRect(-2,-2,_loc1_.width + 4,_loc1_._height + 4);
  315. };
  316. FComboBoxClass.prototype.myOnKillFocus = function()
  317. {
  318.    var _loc1_ = this;
  319.    if(Selection.getFocus().indexOf("labelField") == -1)
  320.    {
  321.       super.myOnKillFocus();
  322.       delete _loc1_.fLabel_txt.onKeyDown;
  323.       _loc1_.openOrClose(false);
  324.       _loc1_.highlightTop(false);
  325.    }
  326. };
  327. FComboBoxClass.prototype.setPopUpLocation = function(mcRef)
  328. {
  329.    var _loc1_ = this;
  330.    var _loc3_ = mcRef;
  331.    _loc3_._x = _loc1_._x;
  332.    var _loc2_ = {x:_loc1_._x,y:_loc1_._y + _loc1_.proxyBox_mc._height};
  333.    _loc1_._parent.localToGlobal(_loc2_);
  334.    _loc3_._parent.globalToLocal(_loc2_);
  335.    _loc3_._x = _loc2_.x;
  336.    _loc3_._y = _loc2_.y;
  337.    if(_loc1_.height + _loc3_._y >= Stage.height)
  338.    {
  339.       _loc1_.upward = true;
  340.       _loc3_._y = _loc2_.y - _loc1_.height - _loc1_.proxyBox_mc._height;
  341.    }
  342.    else
  343.    {
  344.       _loc1_.upward = false;
  345.    }
  346. };
  347. FComboBoxClass.prototype.openOrClose = function(flag)
  348. {
  349.    var _loc1_ = this;
  350.    var _loc2_ = flag;
  351.    if(_loc1_.getLength() != 0)
  352.    {
  353.       _loc1_.setPopUpLocation(_loc1_.container_mc);
  354.       if(_loc1_.lastSelected != -1 && (_loc1_.lastSelected < _loc1_.topDisplayed || _loc1_.lastSelected > _loc1_.topDisplayed + _loc1_.numDisplayed))
  355.       {
  356.          super.moveSelBy(_loc1_.lastSelected - _loc1_.getSelectedIndex());
  357.       }
  358.       !_loc2_ ? _loc1_.downArrow.gotoAndStop(1) : _loc1_.downArrow.gotoAndStop(2);
  359.       if(_loc2_ != _loc1_.opened)
  360.       {
  361.          _loc1_.highlightTop(!_loc2_);
  362.          _loc1_.fadeRate = _loc1_.styleTable.popUpFade.value;
  363.          if(!_loc2_ || _loc1_.fadeRate == undefined || _loc1_.fadeRate == 0)
  364.          {
  365.             _loc1_.opened = _loc1_.container_mc._visible = _loc2_;
  366.          }
  367.          else
  368.          {
  369.             _loc1_.setPopUpLocation(_loc1_.fader);
  370.             _loc1_.time = 0;
  371.             _loc1_.const = 85 / Math.sqrt(_loc1_.fadeRate);
  372.             _loc1_.fader._alpha = 85;
  373.             _loc1_.container_mc._visible = _loc1_.fader._visible = true;
  374.             _loc1_.onEnterFrame = function()
  375.             {
  376.                var _loc1_ = this;
  377.                _loc1_.fader._alpha = 100 - (_loc1_.const * Math.sqrt(++_loc1_.time) + 15);
  378.                if(_loc1_.time >= _loc1_.fadeRate)
  379.                {
  380.                   _loc1_.fader._visible = false;
  381.                   delete _loc1_.onEnterFrame;
  382.                   _loc1_.opened = true;
  383.                }
  384.             };
  385.          }
  386.       }
  387.    }
  388. };
  389. FComboBoxClass.prototype.fireChange = function()
  390. {
  391.    var _loc1_ = this;
  392.    _loc1_.lastSelected = _loc1_.getSelectedIndex();
  393.    if(!_loc1_.editable)
  394.    {
  395.       _loc1_.topLabel = _loc1_.getSelectedItem();
  396.       _loc1_.fLabel_mc.drawItem(_loc1_.topLabel,true);
  397.    }
  398.    else
  399.    {
  400.       _loc1_.value = _loc1_.getSelectedItem().label;
  401.       _loc1_.fLabel_mc.setLabel(_loc1_.value);
  402.    }
  403.    _loc1_.executeCallback();
  404. };
  405. FComboBoxClass.prototype.releaseHandler = function()
  406. {
  407.    var _loc1_ = this;
  408.    var _loc2_ = _root;
  409.    var _loc3_ = _loc1_.boundingBox_mc.hitTest(_loc2_._xmouse,_loc2_._ymouse);
  410.    if(_loc1_.changeFlag)
  411.    {
  412.       if(_loc3_)
  413.       {
  414.          _loc1_.fireChange();
  415.       }
  416.       _loc1_.openOrClose(!_loc1_.opened);
  417.    }
  418.    else if(_loc3_)
  419.    {
  420.       _loc1_.openOrClose(false);
  421.    }
  422.    else
  423.    {
  424.       _loc1_.onMouseDown = function()
  425.       {
  426.          var _loc1_ = this;
  427.          var _loc2_ = _root;
  428.          if(!_loc1_.boundingBox_mc.hitTest(_loc2_._xmouse,_loc2_._ymouse) && !_loc1_.hitTest(_loc2_._xmouse,_loc2_._ymouse))
  429.          {
  430.             _loc1_.onMouseDown = undefined;
  431.             _loc1_.openOrClose(false);
  432.          }
  433.       };
  434.    }
  435.    _loc1_.changeFlag = false;
  436.    _loc1_.onMouseUp = undefined;
  437.    clearInterval(_loc1_.dragScrolling);
  438.    _loc1_.dragScrolling = undefined;
  439. };
  440. FComboBoxClass.prototype.moveSelBy = function(itemNum)
  441. {
  442.    var _loc1_ = this;
  443.    if(itemNum != 0)
  444.    {
  445.       super.moveSelBy(itemNum);
  446.       if(_loc1_.editable)
  447.       {
  448.          _loc1_.setValue(_loc1_.getSelectedItem().label);
  449.       }
  450.       if(!_loc1_.opened)
  451.       {
  452.          if(_loc1_.changeFlag && !_loc1_.isSelected(_loc1_.lastSelected))
  453.          {
  454.             _loc1_.fireChange();
  455.          }
  456.       }
  457.    }
  458. };
  459. FComboBoxClass.prototype.myOnKeyDown = function()
  460. {
  461.    var _loc1_ = this;
  462.    if(_loc1_.focused)
  463.    {
  464.       if(_loc1_.editable && Key.isDown(13))
  465.       {
  466.          _loc1_.setValue(_loc1_.fLabel_mc.getLabel());
  467.          _loc1_.executeCallback();
  468.          _loc1_.openOrClose(false);
  469.       }
  470.       else if((Key.isDown(13) || Key.isDown(32) && !_loc1_.editable) && _loc1_.opened)
  471.       {
  472.          if(_loc1_.getSelectedIndex() != _loc1_.lastSelected)
  473.          {
  474.             _loc1_.fireChange();
  475.          }
  476.          _loc1_.openOrClose(false);
  477.          _loc1_.fLabel_txt.hscroll = 0;
  478.       }
  479.       super.myOnKeyDown();
  480.    }
  481. };
  482. FComboBoxClass.prototype.findInputText = function()
  483. {
  484.    if(!this.editable)
  485.    {
  486.       super.findInputText();
  487.    }
  488. };
  489. FComboBoxClass.prototype.onLabelFocus = function()
  490. {
  491.    var _loc1_ = this;
  492.    _loc1_._parent._parent.tabFocused = false;
  493.    _loc1_._parent._parent.focused = true;
  494.    _loc1_.onKeyDown = function()
  495.    {
  496.       this._parent._parent.myOnKeyDown();
  497.    };
  498.    Key.addListener(_loc1_);
  499. };
  500. FComboBoxClass.prototype.buttonPressHandler = function()
  501. {
  502.    this._parent.pressHandler();
  503. };
  504.